/******************************************************************************
 * * sms_api.c - implementation of sms api functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "sms_include.h"

INT8 *Numberglobal = NULL;
INT8 *pSmsTextglobal = NULL;
extern TASK_HANDLE *gui_task_id;
/**
 * send new sms cnf
 * param (in) pSendSmsCnf: MMI_Modem_Send_Sms_Cnf_t
 * return  VOID
 */
VOID Phone_Modem_Send_Sms_Cnf(MMI_Modem_Send_Sms_Cnf_t *pSendSmsCnf)
{

}

#if USE_LV_INTERPHONE_TEST == 0
/**
 * send new sms cnf
 * param (in) pSendSmsCnf: MMI_Modem_Send_Sms_Cnf_t
 * return  VOID
 */
VOID Phone_Modem_Send_Sms_Cnf_Handler(MMI_Modem_Send_Sms_Cnf_t *pSendSmsCnf)
{
    Msg_Content_Info_t *pSentboxMsgContentInfo = NULL;
    ACTIVITY_ID TopAct = Nav_Get_Top();

    if (NULL != g_MsgGlobalCtrl.pSentboxMsgContentInfo)
    {
        pSentboxMsgContentInfo = _lv_ll_get_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
        if (NULL != pSentboxMsgContentInfo)
        {
            pSentboxMsgContentInfo->MsgIndex = pSendSmsCnf->MsgIndex;
            if (MMI_MODEM_SMS_SUCCESS == pSendSmsCnf->Result)
            {
                pSentboxMsgContentInfo->SmsType = MMI_MODEM_SENT;
            }
            else
            {
                pSentboxMsgContentInfo->SmsType = MMI_MODEM_UNSENT;
            }
        }
    }

    if (0 != g_MsgGlobalCtrl.ContactCnt)
    {   // send to many or list
        g_MsgGlobalCtrl.SendCnt++;
        if (NULL != g_MsgGlobalCtrl.pCurrentSend)
        {
            if (MMI_MODEM_SMS_SUCCESS == pSendSmsCnf->Result)
            {
                g_MsgGlobalCtrl.SuccessCnt++;
                g_MsgGlobalCtrl.pCurrentSend->Result = MSG_SUCCESS;
            }
            else
            {
                g_MsgGlobalCtrl.pCurrentSend->Result = MSG_FAIL;
            }

            if (true == g_MsgGlobalCtrl.ResendFlg)
            {
                Sms_Send_To_Many_Sending_Rep_Failed_Resend(NULL,LV_EVENT_CLICKED);
                g_MsgGlobalCtrl.pCurrentSend = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, g_MsgGlobalCtrl.pCurrentSend);
                while (NULL != g_MsgGlobalCtrl.pCurrentSend)
                {
                    if (MSG_FAIL == g_MsgGlobalCtrl.pCurrentSend->Result)
                    {
                        break;
                    }
                    g_MsgGlobalCtrl.pCurrentSend = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, g_MsgGlobalCtrl.pCurrentSend);
                }
            }
            else
            {
                if((ACT_ID_CALL_EMERGENCY_CALLING > TopAct) || (ACT_ID_CALL_DTMF_INPUT < TopAct))
                {
                    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SENDING_STATUS, NULL, NULL);
                }

                g_MsgGlobalCtrl.pCurrentSend = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, g_MsgGlobalCtrl.pCurrentSend);
            }
            if (NULL != g_MsgGlobalCtrl.pCurrentSend)
            {
                Sms_Com_Send_Sms_To_List_Req();
            }
            else
            {
                if((ACT_ID_CALL_EMERGENCY_CALLING <= TopAct) && (ACT_ID_CALL_DTMF_INPUT >= TopAct))
                {
                    Nav_Forward(ACT_ID_MESSAGES_SENDING_STATUS, ACT_ID_MESSAGES, NULL, NULL);
                }
                else
                {
                    Sms_Send_To_Many_Sending_Sts_Stop(NULL);
                }
            }
        }
    }
    else if (NULL != g_MsgGlobalCtrl.pContact)
    {    // send to one
        if((ACT_ID_CALL_EMERGENCY_CALLING <= TopAct) && (ACT_ID_CALL_DTMF_INPUT >= TopAct))
        {
            Nav_Forward(ACT_ID_MESSAGES_SENDING_STATUS, ACT_ID_MESSAGES, NULL, NULL);
        }
        else
        {
            Sms_Create_Message_Sent_Result(pSendSmsCnf->Result);
        }
    }
    Hal_Mem_Free(pSendSmsCnf);
} /* MMI_Modem_Send_Sms_Cnf */
#endif

/**
 * delete sms cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
VOID Phone_Modem_Delete_Sms_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    if (MMI_MODEM_SMS_FAIL == Result)
    {
        // assert
    }
}

/**
 * read sms info cnf
 * param (in) pReadSmsInfoCnf: MMI_Modem_Read_Sms_Info_Cnf_t
 * return  void
 */
VOID Phone_Modem_Read_Sms_Info_Cnf_Handler(MMI_Modem_Read_Sms_Info_Cnf_t *pReadSmsInfoCnf)
{
    UINT32 Id = MSG_INVAILD_TIMER_ID;
    UINT32                                 i            = 0;
    Msg_Content_Info_t                     *pNode       = NULL;
    MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *pReadSmsReq = NULL;

    if (pReadSmsInfoCnf->Result == MMI_MODEM_SMS_FAIL)
    {
        return;// asssert
    }
    if (0 == pReadSmsInfoCnf->ReadMsgCnt)
    {
        switch (g_MsgGlobalCtrl.CurOpenBox)
        {
        case MSG_INBOX:
            Sms_Inbox_Empty();
            g_MsgGlobalCtrl.CurOpenBox = INVAILD_ID;
            break;

        case MSG_DEL_INBOX_ONEBYONE:
        case MSG_DEL_INBOX_ALLREAD:
        case MSG_DEL_INBOX_ALL:
            Sms_Delete_Inbox_Folder_Sts();
            break;

        case MSG_SENT_ITEMS:
            Sms_Sent_Items_Empty();
            g_MsgGlobalCtrl.CurOpenBox = INVAILD_ID;
            break;

        case MSG_DEL_SENT_ITEMS_ONEBYONE:
        case MSG_DEL_SENT_ITEMS_ALLREAD:
            Sms_Delete_Sent_Items_Folder_Sts();
            break;

        case SCREENED_MESSAGES:
            Sms_Scrn_Empty();
            g_MsgGlobalCtrl.CurOpenBox = INVAILD_ID;
            break;

        case DEL_SCREENED_MESSAGES_ONEBYONE:
        case DEL_SCREENED_MESSAGES_ALLREAD:
        case DEL_SCREENED_MESSAGES_ALL:
            Sms_Delete_Scrn_Folder_Sts();
            break;

        case MSG_DEL_ALL_READ:
            Sms_Delete_All_Read_Done(&Id);
            return;

        default:
            break;
        }
        return;
    }

    switch (g_MsgGlobalCtrl.CurOpenBox)
    {
    case MSG_INBOX:
    case MSG_DEL_INBOX_ONEBYONE:
    case MSG_DEL_INBOX_ALLREAD:
    case MSG_DEL_INBOX_ALL:
        if(NULL == g_MsgGlobalCtrl.pInboxMsgContentInfo)
        {
            g_MsgGlobalCtrl.pInboxMsgContentInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
            Hal_Mem_Set(g_MsgGlobalCtrl.pInboxMsgContentInfo, 0, sizeof(lv_ll_t));
            _lv_ll_init(g_MsgGlobalCtrl.pInboxMsgContentInfo, sizeof(Msg_Content_Info_t));
        }

        for (i = 0; i < pReadSmsInfoCnf->ReadMsgCnt; i++)
        {
            pNode = _lv_ll_ins_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
            Hal_Mem_Set(pNode, 0, sizeof(Msg_Content_Info_t));
            pNode->SimId    = pReadSmsInfoCnf->pMsgContentInfo[i].SimId;
            pNode->MsgIndex = pReadSmsInfoCnf->pMsgContentInfo[i].MsgIndex;
            pNode->SmsType  = pReadSmsInfoCnf->pMsgContentInfo[i].ReadSmsType;
        }
        pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        pNode                 = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
        pReadSmsReq->SimId    = pNode->SimId;
        pReadSmsReq->MsgIndex = pNode->MsgIndex;
        printf("Read_Sms_Info_Cnf_Handler is called\n");
        MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
        break;

    case SCREENED_MESSAGES:
    case DEL_SCREENED_MESSAGES_ONEBYONE:
    case DEL_SCREENED_MESSAGES_ALLREAD:
    case DEL_SCREENED_MESSAGES_ALL:
        g_MsgGlobalCtrl.pScrnMsgContentInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pScrnMsgContentInfo, 0, sizeof(lv_ll_t));
        _lv_ll_init(g_MsgGlobalCtrl.pScrnMsgContentInfo, sizeof(Msg_Content_Info_t));

        for (i = 0; i < pReadSmsInfoCnf->ReadMsgCnt; i++)
        {
            pNode = _lv_ll_ins_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
            Hal_Mem_Set(pNode, 0, sizeof(Msg_Content_Info_t));
            pNode->SimId    = pReadSmsInfoCnf->pMsgContentInfo[i].SimId;
            pNode->MsgIndex = pReadSmsInfoCnf->pMsgContentInfo[i].MsgIndex;
            pNode->SmsType  = pReadSmsInfoCnf->pMsgContentInfo[i].ReadSmsType;
        }
        pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        pNode                 = _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
        pReadSmsReq->SimId    = pNode->SimId;
        pReadSmsReq->MsgIndex = pNode->MsgIndex;
        MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
        break;

    case MSG_SENT_ITEMS:
    case MSG_DEL_SENT_ITEMS_ONEBYONE:
    case MSG_DEL_SENT_ITEMS_ALLREAD:
        g_MsgGlobalCtrl.pSentboxMsgContentInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pSentboxMsgContentInfo, 0, sizeof(lv_ll_t));
        _lv_ll_init(g_MsgGlobalCtrl.pSentboxMsgContentInfo, sizeof(Msg_Content_Info_t));

        for (i = 0; i < pReadSmsInfoCnf->ReadMsgCnt; i++)
        {
            pNode = _lv_ll_ins_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
            Hal_Mem_Set(pNode, 0, sizeof(Msg_Content_Info_t));
            pNode->SimId    = pReadSmsInfoCnf->pMsgContentInfo[i].SimId;
            pNode->MsgIndex = pReadSmsInfoCnf->pMsgContentInfo[i].MsgIndex;
            pNode->SmsType  = pReadSmsInfoCnf->pMsgContentInfo[i].ReadSmsType;
        }
        pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
        pNode                 = _lv_ll_get_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
        pReadSmsReq->SimId    = pNode->SimId;
        pReadSmsReq->MsgIndex = pNode->MsgIndex;
        MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
        break;

    case MSG_DEL_ALL_READ:
        Sms_Common_Delete_Sms(MSG_DEL_ALL_READ, (VOID **)&pReadSmsInfoCnf);
        Sms_Delete_All_Read_Done(&Id);
        break;

    default:
        break;
    } /* switch */
    Hal_Mem_Free(pReadSmsInfoCnf->pMsgContentInfo);
    pReadSmsInfoCnf->pMsgContentInfo = NULL;
    Hal_Mem_Free(pReadSmsInfoCnf);
}     /* MMI_Modem_Read_Sms_Info_Cnf */

#if USE_LV_INTERPHONE_TEST == 0
/**
 * read sms detail on sim cnf
 * param (in) pReadSmsCnf: MMI_Modem_Read_Sms_Detail_On_Sim_Cnf_t
 * return  void
 */
VOID Phone_Modem_Read_Sms_Detail_On_Sim_Cnf_Handler(MMI_Modem_Read_Sms_Detail_On_Sim_Cnf_t *pReadSmsCnf)
{
    INT8                                   *pScrnNumList = NULL;
    UINT32                                 i             = 0;
    UINT8                                  Index         = 0;
    Msg_Content_Info_t                     *pNode       = NULL;
    Msg_Content_Info_t                     *pNodeNext   = NULL;
    INT8                                   *Number      = NULL;
    INT8                                   *Time        = NULL;
    INT8                                   *pSmsText    = NULL;
    MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *pReadSmsReq = NULL;

    if (pReadSmsCnf->Result == MMI_MODEM_SMS_FAIL)
    {
        return;// asssert
    }
    // decode sms,get smstext and number
#if MMI_MODEM_SMS_STORE_IN_FILE != 0
    MMI_Modem_Sms_File_DecodeSmsPdu(pReadSmsCnf->pSmsPdu, &Number, &Time, &pSmsText);
#endif

    printf("number %s, time %s, Text %s\n", Number, Time, pSmsText);
    pScrnNumList = Contacts_Get_Num_Scrn_List_Req();
    if (true == g_MsgGlobalCtrl.NewSmsFlg)
    {
        printf("NewSmsFlg is true\n");
        for (i = 0; i < 10; i++)
        {
            Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
            if (false == strcmp(&(pScrnNumList[Index]), Number))
            {
                g_MsgGlobalCtrl.NewSmsFlg = false;
                Hal_Mem_Free(Number);
                g_MsgGlobalCtrl.pNumber = NULL;
                Hal_Mem_Free(pSmsText);
                g_MsgGlobalCtrl.pReadSmsText = NULL;
                Hal_Mem_Free(pReadSmsCnf->pSmsPdu);
                pReadSmsCnf->pSmsPdu = NULL;
                Hal_Mem_Free(pReadSmsCnf);
                return;
            }
        }
        if (10 == i)
        {
            g_MsgGlobalCtrl.UnreadCnt++;
            printf("g_MsgGlobalCtrl.UnreadCnt is %d in Phone_Modem_Read_Sms_Detail_On_Sim_Cnf_Handler\n",g_MsgGlobalCtrl.UnreadCnt);
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
            if ((NULL != pNode) && (pNode->MsgIndex == pReadSmsCnf->MsgIndex) && (pNode->SimId == pReadSmsCnf->SimId))
            {// insert msg
                printf("%s insert new sms to pInboxMsgContentInfo\n", __FUNCTION__);
                pNode->pContact = Number;
            } else {
                printf("fatal error in %s\n", __FUNCTION__);
            }

            Framework_Sms_Unread_Message_Ind(g_MsgGlobalCtrl.UnreadCnt);
        }

        g_MsgGlobalCtrl.NewSmsFlg = false;
        if((MSG_INBOX == g_MsgGlobalCtrl.CurOpenBox) || (MSG_SENT_ITEMS == g_MsgGlobalCtrl.CurOpenBox))
        {
            printf("g_MsgGlobalCtrl.CurOpenBox is %d in Phone_Modem_Read_Sms_Detail_On_Sim_Cnf_Handler but new sms ind\n",g_MsgGlobalCtrl.CurOpenBox);
            Hal_Mem_Free(pReadSmsCnf->pSmsPdu);
            pReadSmsCnf->pSmsPdu = NULL;
            Hal_Mem_Free(pReadSmsCnf);
            return;
        }
    }
    printf("g_MsgGlobalCtrl.CurOpenBox is %d in Phone_Modem_Read_Sms_Detail_On_Sim_Cnf_Handler\n",g_MsgGlobalCtrl.CurOpenBox);
    switch (g_MsgGlobalCtrl.CurOpenBox)
    {
    case MSG_INBOX:
        if (NULL != g_MsgGlobalCtrl.pCurrentViewMsg)
        {    // get one message detail
            printf("pCurrentViewMsg is not null\n");
            g_MsgGlobalCtrl.pReadSmsText              = pSmsText;
            g_MsgGlobalCtrl.pCurrentViewMsg->pContact = Number;
            Sms_Inbox_MsgBody();
            break;
        }
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pInboxMsgContentInfo) == pNode)
        {    // only 1 msg
            printf("only 1 msg\n");
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                printf("MsgIndex is the same\n");
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Inbox_Empty();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pInboxMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pInboxMsgContentInfo)
            {
                printf("pInboxMsgContentInfo is not null\n");
                Sms_Inbox_List(ACT_ID_MESSAGES_OPENING);
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo))
                {
                    Sms_Inbox_Empty();
                }
                else
                {
                    Sms_Inbox_List(ACT_ID_MESSAGES_OPENING);
                }
            }
        }
//        Hal_Mem_Free(pSmsText);
//       pSmsText = NULL;
        break;

    case MSG_DEL_INBOX_ONEBYONE:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pInboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Inbox_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pInboxMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pInboxMsgContentInfo)
            {
                Sms_Del_Inbox_List(ACT_ID_MESSAGES_OPENING);
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo))
                {
                    Sms_Delete_Inbox_Folder_Sts();
                }
                else
                {
                    Sms_Del_Inbox_List(ACT_ID_MESSAGES_OPENING);
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case MSG_DEL_INBOX_ALLREAD:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pInboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Inbox_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pInboxMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pInboxMsgContentInfo)
            {
                Sms_Delete_Inbox_Options_Allread_OK_Sub();
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo))
                {
                    Sms_Delete_Inbox_Folder_Sts();
                }
                else
                {
                    Sms_Delete_Inbox_Options_Allread_OK_Sub();
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case MSG_DEL_INBOX_ALL:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pInboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Inbox_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pInboxMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pInboxMsgContentInfo)
            {
                Sms_Delete_Inbox_Options_All_OK_Sub();
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false == strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pInboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pInboxMsgContentInfo))
                {
                    Sms_Delete_Inbox_Folder_Sts();
                }
                else
                {
                    Sms_Delete_Inbox_Options_All_OK_Sub();
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case SCREENED_MESSAGES:
        if (NULL != g_MsgGlobalCtrl.pCurrentViewMsg)
        {    // get one message detail
            g_MsgGlobalCtrl.pReadSmsText              = pSmsText;
            g_MsgGlobalCtrl.pCurrentViewMsg->pContact = Number;
            Sms_Screened_Msgs_Body(NULL);
            break;
        }
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pScrnMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Scrn_Empty();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pScrnMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pScrnMsgContentInfo)
            {
                Sms_Screened_Msgs_List(ACT_ID_MESSAGES_OPENING);
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo))
                {
                    Sms_Scrn_Empty();
                }
                else
                {
                    Sms_Screened_Msgs_List(ACT_ID_MESSAGES_OPENING);
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case DEL_SCREENED_MESSAGES_ONEBYONE:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pScrnMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Scrn_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pScrnMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pScrnMsgContentInfo)
            {
                Sms_Del_Scrn_List(ACT_ID_MESSAGES_OPENING);
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo))
                {
                    Sms_Delete_Scrn_Folder_Sts();
                }
                else
                {
                    Sms_Del_Scrn_List(ACT_ID_MESSAGES_OPENING);
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case DEL_SCREENED_MESSAGES_ALLREAD:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pScrnMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Scrn_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pScrnMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pScrnMsgContentInfo)
            {
                Sms_Delete_Scrn_Options_Allread_OK_Sub();
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo))
                {
                    Sms_Delete_Scrn_Folder_Sts();
                }
                else
                {
                    Sms_Delete_Scrn_Options_Allread_OK_Sub();
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case DEL_SCREENED_MESSAGES_ALL:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pScrnMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;

                for (i = 0; i < 10; i++)
                {
                    Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                    if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                    {
                        Sms_Delete_Scrn_Folder_Sts();
                        Sms_Common_Free_Msg_Content_Info(&g_MsgGlobalCtrl.pScrnMsgContentInfo);
                        Hal_Mem_Free(Number);
                        g_MsgGlobalCtrl.pNumber = NULL;
                        break;
                    }
                }
            }
            if (NULL != g_MsgGlobalCtrl.pScrnMsgContentInfo)
            {
                Sms_Delete_Scrn_Options_All_OK_Sub();
            }
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                    pNode->pContact = Number;
                    for (i = 0; i < 10; i++)
                    {
                        Index = i * NV_CONTACTS_MAX_NUMBER_LEN;
                        if (false != strcmp(&(pScrnNumList[Index]), pNode->pContact))
                        {
                            _lv_ll_remove(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                            Hal_Mem_Free(pNode);
                            pNode = NULL;
                            Hal_Mem_Free(Number);
                            g_MsgGlobalCtrl.pNumber = NULL;
                            break;
                        }
                    }
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pScrnMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pScrnMsgContentInfo))
                {
                    Sms_Delete_Scrn_Folder_Sts();
                }
                else
                {
                    Sms_Delete_Scrn_Options_All_OK_Sub();
                }
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case MSG_SENT_ITEMS:
        if (NULL != g_MsgGlobalCtrl.pCurrentViewMsg)
        {    // get one message detail
            g_MsgGlobalCtrl.pReadSmsText              = pSmsText;
            g_MsgGlobalCtrl.pCurrentViewMsg->pContact = Number;
            Sms_Sent_Items_Body(NULL);
            break;
        }

        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pSentboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;
            }
            Sms_Sent_Items_List(ACT_ID_MESSAGES_OPENING);
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                Sms_Sent_Items_List(ACT_ID_MESSAGES_OPENING);
            }
        }
//        Hal_Mem_Free(pSmsText);
//        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case MSG_DEL_SENT_ITEMS_ONEBYONE:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pSentboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;
            }
            Sms_Del_Sent_Items_List(ACT_ID_MESSAGES_OPENING);
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                Sms_Del_Sent_Items_List(ACT_ID_MESSAGES_OPENING);
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    case MSG_DEL_SENT_ITEMS_ALLREAD:
        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pSentboxMsgContentInfo);
        if (_lv_ll_get_tail(g_MsgGlobalCtrl.pSentboxMsgContentInfo) == pNode)
        {    // only 1 msg
            if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
               && (pNode->SimId == pReadSmsCnf->SimId))
            {
                pNode->pContact = Number;
            }
            Sms_Delete_Sent_Items_Options_Allread_OK_Sub();
        }
        else
        {    // more than one
            while (NULL != pNode)
            {
                if (  (pNode->MsgIndex == pReadSmsCnf->MsgIndex)
                   && (pNode->SimId == pReadSmsCnf->SimId))
                {
                    pNodeNext       = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                    pNode->pContact = Number;
                }
                if (NULL != pNode)
                {
                    pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pSentboxMsgContentInfo, pNode);
                }
            }
            if ((NULL != pNodeNext))
            {    // get next number
                pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));
                pReadSmsReq->SimId    = pNodeNext->SimId;
                pReadSmsReq->MsgIndex = pNodeNext->MsgIndex;
                MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
            }
            else
            {    // finish get number
                Sms_Delete_Sent_Items_Options_Allread_OK_Sub();
            }
        }
        Hal_Mem_Free(pSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
        break;

    default:
        break;
    } /* switch */
    Hal_Mem_Free(pReadSmsCnf->pSmsPdu);
    pReadSmsCnf->pSmsPdu = NULL;
    Hal_Mem_Free(pReadSmsCnf);
}     /* MMI_Modem_Read_Sms_Detail_On_Sim_Cnf */
#endif

/**
 * get sms centre number cnf
 * param (in) pGetSmscCnf: MMI_Modem_Get_Smsc_Cnf_t
 * return  void
 */
VOID Phone_Modem_Get_Smsc_Cnf_Handler(MMI_Modem_Get_Smsc_Cnf_t *pGetSmscCnf)
{
    UINT32 i      = 0;

    if (pGetSmscCnf->Result == MMI_MODEM_SMS_FAIL)
    {
        return;// asssert
    }
    i                                              = strlen(pGetSmscCnf->pSmsc);
    g_MsgGlobalCtrl.Smsc[pGetSmscCnf->SimId].pSmsc = Hal_Mem_Alloc(i + 1);
    Hal_Mem_Set(g_MsgGlobalCtrl.Smsc[pGetSmscCnf->SimId].pSmsc, 0, i + 1);
    strcpy(g_MsgGlobalCtrl.Smsc[pGetSmscCnf->SimId].pSmsc, pGetSmscCnf->pSmsc);

    if (MMI_MODEM_SIM_1 == pGetSmscCnf->SimId)
    {
        Hal_Mem_Free(pGetSmscCnf->pSmsc);
        pGetSmscCnf->pSmsc = NULL;
        Hal_Mem_Free(pGetSmscCnf);
        MMI_Modem_Get_Smsc_Req(MMI_MODEM_SIM_2);// temp
    }
    else
    {
        Hal_Mem_Free(pGetSmscCnf->pSmsc);
        pGetSmscCnf->pSmsc = NULL;
        Hal_Mem_Free(pGetSmscCnf);
    }
} /* MMI_Modem_Get_Smsc_Cnf */

/**
 * set sms centre number cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
VOID Phone_Modem_Set_Smsc_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    UINT32 Id = MSG_INVAILD_TIMER_ID;
    VOID *pTemp = &Id;
    Sms_Setting_Phone_Num_OK_Timeout(pTemp);
}

/**
 * set delivery report flg cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
VOID Phone_Modem_Set_Delivery_Rep_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SETTING, NULL, NULL);
}
#if 0
void new_sms_info_ind(app_adp_new_sms_info_ind_t *sms_info)
{
    Msg_Content_Info_t                     *pNode = NULL;

    if (NULL == g_MsgGlobalCtrl.pInboxMsgContentInfo)
    {
        g_MsgGlobalCtrl.pInboxMsgContentInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pInboxMsgContentInfo, 0, sizeof(lv_ll_t));
        lv_ll_init(g_MsgGlobalCtrl.pInboxMsgContentInfo, sizeof(Msg_Content_Info_t));
    }
    pNode = lv_ll_ins_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
    Hal_Mem_Set(pNode, 0, sizeof(Msg_Content_Info_t));
    pNode->SimId    = MMI_MODEM_SIM_1;
    pNode->MsgIndex = pRepNewSms->MsgContentInfo.MsgIndex;
    pNode->SmsType  = pRepNewSms->MsgContentInfo.ReadSmsType;
}
#endif

/**
* new sms information indication call back function
* param (in) sms_info: app_adp_new_sms_info_ind_t *
* return  void
*/
void app_adaptor_new_sms_ind(app_adp_new_sms_info_ind_t *sms_info)
{
#if 0
    if(NULL != g_MsgGlobalCtrl.pNumber)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pNumber);
        g_MsgGlobalCtrl.pNumber = NULL;
    }
    if(NULL != g_MsgGlobalCtrl.pReadSmsText)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pReadSmsText);
        g_MsgGlobalCtrl.pReadSmsText = NULL;
    }
    if(NULL != g_MsgGlobalCtrl.pTime)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pTime);
        g_MsgGlobalCtrl.pTime = NULL;
    }
    if(NULL != g_MsgGlobalCtrl.pRcvSmsText)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pRcvSmsText);
        g_MsgGlobalCtrl.pRcvSmsText = NULL;
    }

    g_MsgGlobalCtrl.pTime = Hal_Mem_Alloc(20);
    Hal_Mem_Set(g_MsgGlobalCtrl.pTime,0,20);
    g_MsgGlobalCtrl.pTime[0] = '2';
    g_MsgGlobalCtrl.pTime[1] = '0';
    strncpy(&g_MsgGlobalCtrl.pTime[2],sms_info->time,2);
    g_MsgGlobalCtrl.pTime[4] = '.';
    strncpy(&g_MsgGlobalCtrl.pTime[5],&sms_info->time[2],4);
    g_MsgGlobalCtrl.pTime[9] = '.';
    strncpy(&g_MsgGlobalCtrl.pTime[10],&sms_info->time[6],2);
    g_MsgGlobalCtrl.pTime[12] = ':';
    strncpy(&g_MsgGlobalCtrl.pTime[13],&sms_info->time[8],2);
    g_MsgGlobalCtrl.pTime[15] = ':';
    strncpy(&g_MsgGlobalCtrl.pTime[16],&sms_info->time[10],2);
    Hal_Mem_Set(g_MsgGlobalCtrl.RcvTime,0,20);
    Hal_Mem_Copy(&g_MsgGlobalCtrl.RcvTime,g_MsgGlobalCtrl.pTime,20);

    g_MsgGlobalCtrl.pReadSmsText = Hal_Mem_Alloc(sms_info->data_len + 1);
    Hal_Mem_Set(g_MsgGlobalCtrl.pReadSmsText,0,sms_info->data_len + 1);
    Hal_Mem_Copy(g_MsgGlobalCtrl.pReadSmsText,sms_info->data,sms_info->data_len);
    g_MsgGlobalCtrl.pRcvSmsText = Hal_Mem_Alloc(sms_info->data_len + 1);
    Hal_Mem_Set(g_MsgGlobalCtrl.pRcvSmsText,0,sms_info->data_len + 1);
    Hal_Mem_Copy(g_MsgGlobalCtrl.pRcvSmsText,sms_info->data,sms_info->data_len);
    g_MsgGlobalCtrl.pNumber = Hal_Mem_Alloc(sms_info->number_len);
    Hal_Mem_Set(g_MsgGlobalCtrl.pNumber,0,sms_info->number_len);
    Hal_Mem_Copy(g_MsgGlobalCtrl.pNumber,sms_info->number,sms_info->number_len);
    g_MsgGlobalCtrl.pRcvNumber = Hal_Mem_Alloc(sms_info->number_len);
    Hal_Mem_Set(g_MsgGlobalCtrl.pRcvNumber,0,sms_info->number_len);
    Hal_Mem_Copy(g_MsgGlobalCtrl.pRcvNumber,sms_info->number,sms_info->number_len);
    g_MsgGlobalCtrl.RcvSimId    = (MMI_MODEM_SIM_ID)sms_info->simid;

    printf("pReadSmsText[0] is %d\n",g_MsgGlobalCtrl.pReadSmsText[0]);
    printf("pReadSmsText[1] is %d\n",g_MsgGlobalCtrl.pReadSmsText[1]);
    printf("data[0] is %d\n",sms_info->data[0]);
    printf("data[1] is %d\n",sms_info->data[1]);
    printf("data_len is %d\n",sms_info->data_len);
    printf("number_len is %d\n",sms_info->number_len);
    Msg_Content_Info_t                     *pNode = NULL;
    MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *pReadSmsReq;

    if (NULL == g_MsgGlobalCtrl.pInboxMsgContentInfo)
    {
        g_MsgGlobalCtrl.pInboxMsgContentInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pInboxMsgContentInfo, 0, sizeof(lv_ll_t));
        _lv_ll_init(g_MsgGlobalCtrl.pInboxMsgContentInfo, sizeof(Msg_Content_Info_t));
    }
    pNode = _lv_ll_ins_head(g_MsgGlobalCtrl.pInboxMsgContentInfo);
    Hal_Mem_Set(pNode, 0, sizeof(Msg_Content_Info_t));
    pNode->SimId    = (MMI_MODEM_SIM_ID)sms_info->simid;
    pNode->MsgIndex = 0;
    pNode->SmsType  = MMI_MODEM_UNREAD;
    pNode->pContact = Hal_Mem_Alloc(sms_info->number_len);
    Hal_Mem_Set(pNode->pContact,0,sms_info->number_len);
    Hal_Mem_Copy(pNode->pContact,sms_info->number,sms_info->number_len);
    pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));

    Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));

    pReadSmsReq->MsgIndex = 0;

    pReadSmsReq->SimId = (MMI_MODEM_SIM_ID)sms_info->simid;

    Hal_Mem_Free(sms_info->number);
    Hal_Mem_Free(sms_info->time);
    Hal_Mem_Free(sms_info->data);
    Hal_Mem_Free(sms_info);

    g_MsgGlobalCtrl.NewSmsFlg = true;
    MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);
#endif
}

#if USE_LV_INTERPHONE_TEST == 0
/**
 * report new sms ind
 * param (in) pRepNewSms:MMI_Modem_Report_New_Sms_Ind_t
 * return  void
 */
VOID Phone_Modem_Rep_New_Sms_Ind(MMI_Modem_Report_New_Sms_Ind_t *pRepNewSms)
{
    MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *pReadSmsReq;
    If_Setting_Play_Tone_t *SettingPlayTone = NULL;

    pReadSmsReq = (MMI_Modem_Read_Sms_Detail_On_Sim_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));

    Hal_Mem_Set(pReadSmsReq, 0, sizeof(MMI_Modem_Read_Sms_Detail_On_Sim_Req_t));

    pReadSmsReq->MsgIndex = pRepNewSms->MsgContentInfo.MsgIndex;

    pReadSmsReq->SimId = pRepNewSms->MsgContentInfo.SimId;
    SettingPlayTone =
                (If_Setting_Play_Tone_t *)Hal_Mem_Alloc(sizeof(If_Setting_Play_Tone_t));
            Hal_Mem_Set(SettingPlayTone, 0, sizeof(If_Setting_Play_Tone_t));
            SettingPlayTone->ToneType = IF_SETTING_TONS_TYPE_SMS;
            SettingPlayTone->PlayCtrl = IF_SETTING_PLAY_TONS_START;
            SettingPlayTone->SimId = pReadSmsReq->SimId;
            Setting_Play_Tone_Req(SettingPlayTone);
    g_MsgGlobalCtrl.NewSmsFlg = true;
    MMI_Modem_Read_Sms_Detail_On_Sim_Req(pReadSmsReq);

    Hal_Mem_Free(pRepNewSms);
}

/**
 * report new status report ind
 * param (in) pRepNewStsRep:MMI_Modem_Response_Sms_Status_Rep_Ind_t
 * return  void
 */
VOID Phone_Modem_Sms_Status_Rep_Ind(MMI_Modem_Response_Sms_Status_Rep_Ind_t *pRepNewStsRep)
{
    INT8 *Report = pSmsTextglobal;// for uttest

    // decode report
    Sms_Message_Sent_Rep(Report);
    Hal_Mem_Free(pRepNewStsRep->pSmsStatusRep);
    pRepNewStsRep->pSmsStatusRep = NULL;
    Hal_Mem_Free(pRepNewStsRep);
}
#endif

/**
 * send Ussd cnf
 * param (in) pSendUssdCnf: MMI_Modem_Send_Ussd_Cnf_t
 * return  void
 */
VOID Phone_Modem_Send_Ussd_Cnf(MMI_Modem_Send_Ussd_Cnf_t *pSendUssdCnf)
{
    if (MMI_MODEM_CMD_NOT_CNF == pSendUssdCnf->Result)
    {
        Sms_Ussd_Send_Result_Fail();
    }
    else if (MMI_MODEM_UNKNOWN_CMD == pSendUssdCnf->Result)
    {
        Sms_Ussd_Send_Result(MSG_USSD_UNKNOWN_CMD, NULL);
    }
    else if (MMI_MODEM_CMD_SUCCESS == pSendUssdCnf->Result)
    {
        Sms_Ussd_Send_Result(MSG_USSD_CMD_SUCCESS, pSendUssdCnf->pSendUssdCnf);
    }
    if (NULL != pSendUssdCnf->pSendUssdCnf)
    {
        Hal_Mem_Free(pSendUssdCnf->pSendUssdCnf);
        pSendUssdCnf->pSendUssdCnf = NULL;
    }
    Hal_Mem_Free(pSendUssdCnf);
}

/**
 * Inform SMS APP of the contacts selected in contacts APP
 * param (in) Contact: If_Contacts_Select_Contact_t*
 * return  void
 */
void Contacts_SMS_Select_Contact_Cnf(If_Contacts_Select_t *Contact, UINT16 Count)
{
    UINT32                                i   = 0;
    UINT32                                k   = 0;
    INT8                                  Temp[MSG_TEXT_INPUT_MAX_LEN];
    INT8                                  *pTemp        = NULL;
    Msg_Contact_List_Info_t               *pContactInfo = NULL;
    UI_Normal_NoTitle_Label_Ta_Desc_t     *pNum         = NULL;
    NV_UI_Sms_Distribution_Contact_Name_t *data         = NULL;
    Msg_Distribution_List_Info_t          *pDisListInfo = NULL;

    if (DISTRIBUTION_LISTS == g_MsgGlobalCtrl.CurOpenBox)
    {
        pContactInfo = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
        for (k = 0; NULL != pContactInfo; k++)
        {
            if (false == strcmp(pContactInfo->pContact, Contact->Name))
            {
                Sms_Distribution_Lists_Add_Contact_Cnf(true);
                return;
            }
            pContactInfo = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pContactInfo);
        }
        if (k)
        {
            if (NV_SMS_MAX_LIST_NUM == k)
            {
                Sms_Distribution_Lists_Contact_Full();
                return;
            }
            pContactInfo = _lv_ll_ins_tail(g_MsgGlobalCtrl.pContactInfo);
            Hal_Mem_Set(pContactInfo, 0, sizeof(Msg_Contact_List_Info_t));
        }
        else
        {
            Sms_Common_Free_ContactInfo();
            g_MsgGlobalCtrl.pContactInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
            Hal_Mem_Set(g_MsgGlobalCtrl.pContactInfo, 0, sizeof(lv_ll_t));
            _lv_ll_init(g_MsgGlobalCtrl.pContactInfo, sizeof(Msg_Contact_List_Info_t));
            pContactInfo = _lv_ll_ins_head(g_MsgGlobalCtrl.pContactInfo);
            Hal_Mem_Set(pContactInfo, 0, sizeof(Msg_Contact_List_Info_t));
        }
        if (k < NV_SMS_MAX_LIST_NUM)
        {
            pContactInfo->pContact = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(pContactInfo->pContact, 0, NV_SMS_MAX_NAME_NUM);
            pTemp                      = strcpy(pContactInfo->pContact, Contact[0].Name);
            g_MsgGlobalCtrl.ContactCnt = k + 1;
            pContactInfo->Index        = k;

            pContactInfo->pNum = Hal_Mem_Alloc(NV_CONTACTS_MAX_NUMBER_LEN);
            Hal_Mem_Set(pContactInfo->pNum, 0, NV_CONTACTS_MAX_NUMBER_LEN);
            pTemp = strcpy(pContactInfo->pNum, Contact[0].Number);

            // set the contact info to NVM
            for (i = 0; i < g_MsgGlobalCtrl.pDisList->DistriCnt; i++)
            {
                if (i)
                {
                    pDisListInfo = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pDisListInfo);
                }
                else
                {
                    pDisListInfo = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                }
                if (false == strcmp(pDisListInfo->pListName, g_MsgGlobalCtrl.pDistriListName))
                {
                    break;
                }
            }
            data = (NV_UI_Sms_Distribution_Contact_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
            Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
            UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pDisListInfo->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
            Hal_Mem_Copy(data->ContactName[pContactInfo->Index], pContactInfo->pContact, NV_SMS_MAX_NAME_NUM);
            UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pDisListInfo->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
            Hal_Mem_Free(data);
            data = NULL;

            Sms_Distribution_Lists_Add_Contact_Cnf(false);
        }
    }
    else if (MSG_SETTING == g_MsgGlobalCtrl.CurOpenBox)
    {
        Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_CENTRE_NUM, NULL, NULL);
        pNum = g_MsgGlobalCtrl.pChart;
        lv_textarea_set_text(pNum->ContTa.TextArea, Contact[0].Number);
        pTemp = (INT8 *)lv_textarea_get_text(pNum->ContTa.TextArea);// temp
        i     = strlen(pTemp);
        sprintf(Temp, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN - i);
        lv_label_set_text(pNum->ContLabelTr.Label, Temp);                                    // temp
        lv_label_set_text((lv_obj_t *)pNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_OK)); // temp
    }
    else
    {
        if (IF_CONTACTS_SMS_SEL_ONE_CONTACT == g_MsgGlobalCtrl.SelContactType)
        {
            if (false == g_MsgGlobalCtrl.InsertNumFlg)
            {
                Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_PHONE_NUMBER, NULL, NULL);
            }
            else
            {
                g_MsgGlobalCtrl.InsertNumFlg = false;
                Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_INSERT_NUMBER, NULL, NULL);
            }
            pNum = g_MsgGlobalCtrl.pChart;
            lv_textarea_set_text(pNum->ContTa.TextArea, Contact[0].Number);
            pTemp = (INT8 *)lv_textarea_get_text(pNum->ContTa.TextArea);// temp
            i     = strlen(pTemp);
            sprintf(Temp, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN - i);
            lv_label_set_text(pNum->ContLabelTr.Label, Temp);                                    // temp
            lv_label_set_text((lv_obj_t *)pNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_OK)); // temp
        }
        else
        {
            Sms_Common_Free_ContactInfo();
            if (Count > 0)
            {
                g_MsgGlobalCtrl.pContactInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
                Hal_Mem_Set(g_MsgGlobalCtrl.pContactInfo, 0, sizeof(lv_ll_t));
                g_MsgGlobalCtrl.ContactCnt = 0;
                _lv_ll_init(g_MsgGlobalCtrl.pContactInfo, sizeof(Msg_Contact_List_Info_t));

                while (g_MsgGlobalCtrl.ContactCnt != Count)
                {
                    if (g_MsgGlobalCtrl.ContactCnt)
                    {
                        pContactInfo = _lv_ll_ins_tail(g_MsgGlobalCtrl.pContactInfo);
                        Hal_Mem_Set(pContactInfo, 0, sizeof(Msg_Contact_List_Info_t));
                    }
                    else
                    {
                        pContactInfo = _lv_ll_ins_head(g_MsgGlobalCtrl.pContactInfo);
                        Hal_Mem_Set(pContactInfo, 0, sizeof(Msg_Contact_List_Info_t));
                    }
                    pContactInfo->pContact = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
                    Hal_Mem_Set(pContactInfo->pContact, 0, NV_SMS_MAX_NAME_NUM);
                    pTemp               = strcpy(pContactInfo->pContact, Contact[k].Name);
                    pContactInfo->Index = k;
                    g_MsgGlobalCtrl.ContactCnt++;
                    pContactInfo->pNum = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
                    Hal_Mem_Set(pContactInfo->pNum, 0, NV_SMS_MAX_NAME_NUM);
                    pTemp = strcpy(pContactInfo->pNum, Contact[k].Number);
                    k++;
                }
                Sms_Send_To_Many_Sending_Sts();
                g_MsgGlobalCtrl.pCurrentSend = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
            }
            if (NULL != g_MsgGlobalCtrl.pCurrentSend)
            {
                Sms_Com_Send_Sms_To_List_Req();
            }
        }
    }
    Hal_Mem_Free(Contact);
} /* Contacts_SMS_Select_Contact_Cnf */

/**
 * SMS request from contacts APP
 * param (in) Name: char*
 * param (in) Number: char*
 * return  VOID
 */
VOID Contacts_SMS_Req(INT8 *Name, INT8 *Number)
{
    UINT32   i      = 0;

    g_MsgGlobalCtrl.OtherAppUseType = CONTACTS_SMS_REQ;
    i = strlen(Number);

    if (i)
    {
        g_MsgGlobalCtrl.pContact = Hal_Mem_Alloc(i + 1);
        Hal_Mem_Set(g_MsgGlobalCtrl.pContact, 0, i + 1);
        strcpy(g_MsgGlobalCtrl.pContact, Number);
    }
    Sms_Create(NULL,LV_EVENT_CLICKED);
}

/**
 * Send phone number by SMS request from contacts APP
 * param (in) Name: char*
 * param (in) Number: char*
 * return  VOID
 */
VOID Contacts_Share_Via_SMS_Req(INT8 *Name, INT8 *Number)
{
    UINT32   i      = 0;
    INT8     str[72];

    g_MsgGlobalCtrl.OtherAppUseType = CONTACTS_SHARE_VIA_SMS_REQ;
    Hal_Mem_Set(str, 0, 72);
    strcat(str, Name);
    strcat(str, "\n");
    strcat(str, Number);
    i     = strlen(str);
    if (i)
    {
        g_MsgGlobalCtrl.pSmsText = Hal_Mem_Alloc(i + 1);
        Hal_Mem_Set(g_MsgGlobalCtrl.pSmsText, 0, i + 1);
        strcpy(g_MsgGlobalCtrl.pSmsText, str);
    }
    Sms_Create(NULL,LV_EVENT_CLICKED);
}

/**
 * Call app send SMS or send the number to others
 * param (in) char* cNumber,char* Message
 * return  void
 */
VOID Call_Send_Sms_Req(INT8 *Number, INT8 *Message)
{
    UINT32   i      = 0;

    g_MsgGlobalCtrl.OtherAppUseType = CALL_SEND_SMS_REQ;
    if (NULL != Number)
    {
        i = strlen(Number);
        if (i)
        {
            g_MsgGlobalCtrl.pContact = Hal_Mem_Alloc(i + 1);
            Hal_Mem_Set(g_MsgGlobalCtrl.pContact, 0, i + 1);
            strcpy(g_MsgGlobalCtrl.pContact, Number);
        }
    }
    if (NULL != Message)
    {
        i = strlen(Message);
        if (i)
        {
            g_MsgGlobalCtrl.pSmsText = Hal_Mem_Alloc(i + 1);
            Hal_Mem_Set(g_MsgGlobalCtrl.pSmsText, 0, i + 1);
            strcpy(g_MsgGlobalCtrl.pSmsText, Message);
        }
    }
    Sms_Create(NULL,LV_EVENT_CLICKED);
} /* Call_Send_Sms_Req */

/**
 * Call app inform message app the MT call Incoming
 * param (in)void
 * return  void
 */
VOID Call_Inform_Sms_Mt_Call_Incoming(VOID)
{
}

/**
 * Open SMS inbox
 * param (in)void
 * return  void
 */
VOID Framework_Sms_Open_Inbox_Req(VOID)
{
    g_MsgGlobalCtrl.OtherAppUseType = FRAMEWORK_SMS_OPEN_INBOX_REQ;
    Sms_Inbox(NULL,LV_EVENT_CLICKED);
}

/**
 * Send message request
 * param (in) Number: INT8 *
 * return  VOID
 */
VOID Framework_Sms_Send_Message_Req(INT8 *Number)
{
    UINT32   i      = 0;

    g_MsgGlobalCtrl.OtherAppUseType = FRAMEWORK_SMS_SEND_MESSAGE_REQ;
    i = strlen(Number);
    if (i)
    {
        g_MsgGlobalCtrl.pContact = Hal_Mem_Alloc(i + 1);
        Hal_Mem_Set(g_MsgGlobalCtrl.pContact, 0, i + 1);
        strcpy(g_MsgGlobalCtrl.pContact, Number);
    }
    Sms_Create(NULL,LV_EVENT_CLICKED);
}

/**
 * report SMS storage status of SIM
 * param (in) pRepSimSmsStaInd: MMI_Modem_SIM_SMS_Storage_Status_Ind
 * return  void
 */
VOID Phone_Modem_SIM_SMS_Storage_Status_Ind(MMI_Modem_SIM_SMS_Storage_Status_Ind_t *pRepSimSmsStaInd)
{
    if (NULL == pRepSimSmsStaInd)
    {
        // assert
        return;
    }
    if (true == pRepSimSmsStaInd->SimFull)
    {
        Sms_Sim_Storeage_Full(pRepSimSmsStaInd->SimId);
    }
    Hal_Mem_Free(pRepSimSmsStaInd);
}

/**
 * IME config req
 * param (in) IMEConfigReq:IF_IME_CONFIG_REQ
 * return  void
 */
VOID IME_Config_Req(IF_IME_CONFIG_REQ IMEConfigReq)
{
    // dummy
}
